*----------------------------------------------------------------------*
***INCLUDE LYBC_SWS_SEND_REQUESTF01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form FRM_GET_NUMBER
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- LS_REQUEST_REQUESTID
*&---------------------------------------------------------------------*
FORM FRM_GET_NUMBER  CHANGING CV_NUM.
  CLEAR CV_NUM.

  CALL FUNCTION 'NUMBER_RANGE_ENQUEUE'
    EXPORTING
      OBJECT           = 'YBC_SWS_NO'
    EXCEPTIONS
      FOREIGN_LOCK     = 1
      OBJECT_NOT_FOUND = 2
      SYSTEM_FAILURE   = 3
      OTHERS           = 4.
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.

  CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
      NR_RANGE_NR             = '01' "
      OBJECT                  = 'YBC_SWS_NO'
    IMPORTING
      NUMBER                  = CV_NUM
*     QUANTITY                =
*     RETURNCODE              =
    EXCEPTIONS
      INTERVAL_NOT_FOUND      = 1
      NUMBER_RANGE_NOT_INTERN = 2
      OBJECT_NOT_FOUND        = 3
      QUANTITY_IS_0           = 4
      QUANTITY_IS_NOT_1       = 5
      INTERVAL_OVERFLOW       = 6
      BUFFER_OVERFLOW         = 7
      OTHERS                  = 8.
  IF SY-SUBRC <> 0.

  ENDIF.

  CALL FUNCTION 'NUMBER_RANGE_DEQUEUE'
    EXPORTING
      OBJECT           = 'YBC_SWS_NO'
    EXCEPTIONS
      OBJECT_NOT_FOUND = 1
      OTHERS           = 2.
  IF SY-SUBRC <> 0.
* Implement suitable error handling here
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_CREATE_USER
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- LS_USER
*&---------------------------------------------------------------------*
FORM FRM_CREATE_USER  CHANGING CS_USER TYPE YBC_SWS_USER
                               CS_MSG TYPE BAPIRET2.
  DATA:
      LV_PERSNUMBER    TYPE AD_PERSNUM. "Person Number

  CLEAR CS_MSG.

  "获取用户名称及邮箱等信息在YBC_SWS_GET_APPROVER 此处不需要再重复取
  DATA:
    LV_USERNAME TYPE BAPIBNAME-BAPIBNAME,
    LS_RET2     TYPE BAPIRET2,
    LT_RET2     TYPE STANDARD TABLE OF BAPIRET2.

  LV_USERNAME = CS_USER-SAPID.
  CALL FUNCTION 'BAPI_USER_GET_DETAIL'
    EXPORTING
      USERNAME = LV_USERNAME
*     CACHE_RESULTS        = 'X'
* IMPORTING
*     LOGONDATA            =
    TABLES
      RETURN   = LT_RET2.

  LOOP AT LT_RET2 INTO LS_RET2 WHERE TYPE = 'E' OR TYPE = 'A'.
    CS_MSG = LS_RET2.
    CS_MSG-TYPE = 'E'.
    EXIT.
  ENDLOOP.
  IF CS_MSG-TYPE = 'E'.
    RETURN.
  ENDIF.

  TRY .
      CS_USER-USERID = CL_SYSTEM_UUID=>CREATE_UUID_C32_STATIC( ).
    CATCH CX_UUID_ERROR.
      CS_MSG-TYPE = 'E'.
      MESSAGE S009(YBC_SWS) INTO CS_MSG-MESSAGE.
      RETURN.
  ENDTRY.

  IF CS_USER-CRUSER IS INITIAL.
    CS_USER-PWD_INIT = 'X'.
    CS_USER-PASSWORD = GC_INIT_PWD.
    CS_USER-CRUSER = SY-UNAME.
    CS_USER-CRDATE = SY-DATUM.
    CS_USER-CRTIME = SY-UZEIT.
  ELSE.
    CS_USER-LAUSER = SY-UNAME.
    CS_USER-LADATE = SY-DATUM.
    CS_USER-LATIME = SY-UZEIT.
  ENDIF.

  CLEAR:    "Add by wangpeng for Zeekr IDP project
   CS_USER-NAME2,
   CS_USER-NAME3.

* 审批人的名字， 要取ADRP-NAME_TEXT，但是GR 的审批流 中的名字，是取的 YBC_SWS_USER-NAME1
* 所以直接更新  YBC_SWS_USER-NAME1.
  CLEAR LV_PERSNUMBER.
  SELECT SINGLE
    PERSNUMBER
    INTO LV_PERSNUMBER
    FROM USR21
    WHERE BNAME = CS_USER-SAPID.
  IF SY-SUBRC = 0.
    SELECT SINGLE
      NAME_TEXT
      INTO CS_USER-NAME1
      FROM ADRP
      WHERE PERSNUMBER = LV_PERSNUMBER.
    CONCATENATE CS_USER-NAME1 '(' CS_USER-SAPID ')'
      INTO CS_USER-NAME1.
  ENDIF.

  MODIFY YBC_SWS_USER FROM CS_USER.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_FORMAT_VALUE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> LS_TEMPL_H_ZFORMAT
*&      --> LS_FVALUE_H_VALUE
*&      <-- IT_HEAD_DATA_VALUE
*&---------------------------------------------------------------------*
FORM FRM_FORMAT_VALUE  USING    VALUE(IV_FNAME)
                                VALUE(IV_ZFORMAT) TYPE YBC_SWS_TEMPL_H-ZFORMAT
                                VALUE(IV_VALUE)
                       CHANGING CV_VALUE.

  DATA:
    LV_RS38L_FNAM TYPE RS38L_FNAM,
    LV_CONVEXIT   TYPE DD01L-CONVEXIT,
    LV_STR        TYPE TEXT100,
    LV_STR1       TYPE TEXT40,
    LV_DATE       TYPE SY-DATUM,
    LV_TIME       TYPE SY-UZEIT,
    LV_DECIMALS   TYPE I VALUE '999',
    LV_DEC_IN     TYPE P DECIMALS 6,
    LV_DEC_OUT0   TYPE P DECIMALS 0,
    LV_DEC_OUT1   TYPE P DECIMALS 1,
    LV_DEC_OUT2   TYPE P DECIMALS 2,
    LV_DEC_OUT3   TYPE P DECIMALS 3,
    LV_DEC_OUT4   TYPE P DECIMALS 4.

  FIELD-SYMBOLS <FS_DEC_OUT>.

  CONDENSE: IV_VALUE, IV_FNAME.
  CHECK IV_VALUE IS NOT INITIAL AND IV_VALUE <> SPACE.

  CASE IV_ZFORMAT.
    WHEN '' OR SPACE.
      CV_VALUE = IV_VALUE.

    WHEN '01'. "日期
      LV_DATE = IV_VALUE.
      CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
        EXPORTING
          DATE                      = LV_DATE
        EXCEPTIONS
          PLAUSIBILITY_CHECK_FAILED = 1
          OTHERS                    = 2.
      IF SY-SUBRC <> 0.
        CV_VALUE = IV_VALUE.

      ELSE.
        CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
          EXPORTING
            DATE_INTERNAL            = LV_DATE
          IMPORTING
            DATE_EXTERNAL            = CV_VALUE
          EXCEPTIONS
            DATE_INTERNAL_IS_INVALID = 1
            OTHERS                   = 2.
        IF SY-SUBRC <> 0.
          CV_VALUE = IV_VALUE.
        ENDIF.
      ENDIF.

    WHEN '02'. "时间
      LV_TIME = IV_VALUE.
      CALL FUNCTION 'TIME_CHECK_PLAUSIBILITY'
        EXPORTING
          TIME                      = LV_TIME
        EXCEPTIONS
          PLAUSIBILITY_CHECK_FAILED = 1
          OTHERS                    = 2.
      IF SY-SUBRC <> 0.
        CV_VALUE = IV_VALUE.
      ELSE.
        WRITE IV_VALUE TO CV_VALUE USING EDIT MASK '__:__:__'. "Format control to time HHHH:MM:SS
      ENDIF.

    WHEN '03'. "日期时间
      LV_DATE = IV_VALUE+0(8).
      LV_STR = IV_VALUE+8.
      CONDENSE LV_STR.
      LV_TIME = LV_STR.

      CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
        EXPORTING
          DATE                      = LV_DATE
        EXCEPTIONS
          PLAUSIBILITY_CHECK_FAILED = 1
          OTHERS                    = 2.
      IF SY-SUBRC <> 0.
        CV_VALUE = IV_VALUE.
      ELSE.

        CLEAR LV_STR.
        CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'
          EXPORTING
            DATE_INTERNAL            = LV_DATE
          IMPORTING
            DATE_EXTERNAL            = LV_STR
          EXCEPTIONS
            DATE_INTERNAL_IS_INVALID = 1
            OTHERS                   = 2.
        IF SY-SUBRC <> 0.
          CV_VALUE = IV_VALUE.

        ELSE.
          CALL FUNCTION 'TIME_CHECK_PLAUSIBILITY'
            EXPORTING
              TIME                      = LV_TIME
            EXCEPTIONS
              PLAUSIBILITY_CHECK_FAILED = 1
              OTHERS                    = 2.
          IF SY-SUBRC <> 0.
            CV_VALUE = IV_VALUE.
          ELSE.
            CLEAR LV_STR1.
            WRITE LV_TIME TO LV_STR1 USING EDIT MASK '__:__:__'. "Format control to time HHHH:MM:SS
            CONDENSE LV_STR1.
            CONCATENATE LV_STR LV_STR1 INTO CV_VALUE SEPARATED BY SPACE.
          ENDIF.
        ENDIF.
      ENDIF.

    WHEN '04'. "数字0位小数
      ASSIGN LV_DEC_OUT0 TO <FS_DEC_OUT>.
      LV_DECIMALS = 0.

    WHEN '05'. "数字1位小数
      ASSIGN LV_DEC_OUT1 TO <FS_DEC_OUT>.
      LV_DECIMALS = 1.

    WHEN '06'. "数字2位小数
      ASSIGN LV_DEC_OUT2 TO <FS_DEC_OUT>.
      LV_DECIMALS = 2.

    WHEN '07'. "数字3位小数
      ASSIGN LV_DEC_OUT3 TO <FS_DEC_OUT>.
      LV_DECIMALS = 3.

    WHEN '08'. "数字4位小数
      ASSIGN LV_DEC_OUT4 TO <FS_DEC_OUT>.
      LV_DECIMALS = 4.

    WHEN '09'. "内外部转换
      CLEAR LV_CONVEXIT.
      SELECT SINGLE
        DD01L~CONVEXIT
        INTO LV_CONVEXIT
        FROM DD04L
        JOIN DD01L
          ON DD04L~DOMNAME = DD01L~DOMNAME
         AND DD04L~AS4LOCAL = DD01L~AS4LOCAL
       WHERE DD04L~ROLLNAME = IV_FNAME
         AND DD04L~AS4LOCAL = 'A'.
      IF SY-SUBRC <> 0 OR LV_CONVEXIT IS INITIAL.
        CV_VALUE = IV_VALUE.

      ELSE.
        CONDENSE LV_CONVEXIT.
        LV_RS38L_FNAM = 'CONVERSION_EXIT_' && LV_CONVEXIT && '_OUTPUT'.
        SELECT COUNT(*)
          FROM TFDIR
         WHERE FUNCNAME = LV_RS38L_FNAM.

        IF SY-SUBRC <> 0.
          CV_VALUE = IV_VALUE.
        ELSE.
          CALL FUNCTION LV_RS38L_FNAM
            EXPORTING
              INPUT  = IV_VALUE
            IMPORTING
              OUTPUT = CV_VALUE.
        ENDIF.
      ENDIF.

    WHEN '10'. "去前导零
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
        EXPORTING
          INPUT  = IV_VALUE
        IMPORTING
          OUTPUT = CV_VALUE.

    WHEN OTHERS.
      CV_VALUE = IV_VALUE.
  ENDCASE.

  IF LV_DECIMALS <> '999'.
    CALL FUNCTION 'CATS_NUMERIC_INPUT_CHECK'
      EXPORTING
        INPUT      = IV_VALUE
*       INTERNAL   = 'X'
      IMPORTING
        OUTPUT     = IV_VALUE
      EXCEPTIONS
        NO_NUMERIC = 1
        OTHERS     = 2.
    IF SY-SUBRC <> 0.
      CV_VALUE = IV_VALUE.
    ELSE.
      LV_DEC_IN = IV_VALUE.
      CALL FUNCTION 'ROUND'
        EXPORTING
          DECIMALS      = LV_DECIMALS
          INPUT         = LV_DEC_IN
       "  SIGN          = '-'
        IMPORTING
          OUTPUT        = <FS_DEC_OUT>
        EXCEPTIONS
          INPUT_INVALID = 1
          OVERFLOW      = 2
          TYPE_INVALID  = 3
          OTHERS        = 4.
      IF SY-SUBRC <> 0.
        CV_VALUE = IV_VALUE.
      ELSE.
        CLEAR LV_STR.
        LV_STR = <FS_DEC_OUT>.
        CONDENSE LV_STR.
        PERFORM FRM_DEC_OUTPUT USING LV_STR CHANGING LV_STR.
        CONDENSE LV_STR.
        CV_VALUE = LV_STR.
      ENDIF.
    ENDIF.
  ENDIF.

  CONDENSE CV_VALUE.
ENDFORM.

FORM FRM_DEC_OUTPUT USING IV_NUM
      CHANGING CV_NUM .

  DATA :L_STR1  TYPE STRING .
  DATA :L_STR2  TYPE STRING .


  DATA : L_LEN   TYPE  I,
         L_COUNT TYPE  I,
         L_CHAR  TYPE STRING,
         L_POS   TYPE  I,
         L_REST  TYPE  I,
         L_TIME  TYPE  I,
         L_FLAG .
  CONSTANTS : C_TAB VALUE  ',',
              C_POT VALUE  '.'.

  CLEAR:
       L_LEN ,
       L_COUNT ,
       L_CHAR ,
       L_POS ,
       L_REST ,
       L_TIME ,
       L_STR1 ,
       L_STR2 ,
       L_FLAG .

  CHECK IV_NUM  IS  NOT  INITIAL .
  IF IV_NUM  CS C_POT .
    SPLIT IV_NUM  AT C_POT  INTO L_STR1 L_STR2 .
    L_FLAG  =  'X' .
  ELSE .
    L_STR1  = IV_NUM .
  ENDIF .


  L_LEN  =  STRLEN( L_STR1 ).
  L_COUNT  = L_LEN .
  L_REST  = L_LEN  MOD  3 .
  IF L_REST  =  0 .
    L_TIME  = L_LEN  DIV  3 .
  ELSE .
    L_TIME  = L_LEN  DIV  3 +  1 .
  ENDIF .
  DO L_TIME  TIMES .
    L_COUNT  = L_COUNT  -  3 .
    IF L_COUNT >  0 .
      CONCATENATE C_TAB L_STR1+L_COUNT(3) L_CHAR  INTO L_CHAR .
    ELSEIF L_COUNT <=  0 .
      L_COUNT  = L_COUNT +  3 .
      CONCATENATE L_STR1+0(L_COUNT) L_CHAR  INTO L_CHAR .
      EXIT .
    ENDIF .
  ENDDO .

  CV_NUM  = L_CHAR .
  CONDENSE CV_NUM  NO-GAPS .
  IF L_FLAG  IS  NOT  INITIAL .
    CONCATENATE CV_NUM C_POT L_STR2  INTO CV_NUM .
  ENDIF .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_SET_HTML_HEADER
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- LV_HTML
*&---------------------------------------------------------------------*
FORM FORM_SET_HTML_HEADER USING IV_TITLE TYPE STRING
                          CHANGING CV_HTML TYPE STRING.
  CLEAR CV_HTML.

  CV_HTML = '<html><head><title>' && IV_TITLE && '</title>' &&
            '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />' &&
            '</head><body>'.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_PREPARE_MAIL_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> LS_CREATOR
*&      --> LS_USER
*&      --> LS_REQUEST
*&      <-- LS_MAIL
*&---------------------------------------------------------------------*
FORM FORM_PREPARE_MAIL_DATA  USING    IV_CNFG_LANGU TYPE YBC_SWS_APP_CNFG-MAIL_LANGU
                                      IS_CREATOR TYPE YBC_SWS_USER
                                      IS_APPROVER TYPE YBC_SWS_USER
                                      IS_REQUEST TYPE YBC_SWS_REQUEST
                             CHANGING CS_MAIL TYPE YBCS_SWS_MAIL
                                      CV_MAIL_ERROR TYPE C.

  DATA:
    LV_MAIL_LANGU   TYPE YBC_SWS_USER-MAIL_LANGU,
    LV_HTML         TYPE STRING,
    LV_TEXT         TYPE STRING,
    LS_SWS_CONTR    TYPE YBC_SWS_CONTR,
    LV_APPROVER     TYPE STRING,
    LV_CREATOR      TYPE STRING,
    LV_REQINFO      TYPE STRING,
    LV_REQURL       TYPE STRING,
    LV_TIMES        TYPE I,
    LV_MSGNR_LAST   TYPE I,
    LT_T100         TYPE STANDARD TABLE OF T100,
    LS_T100         TYPE T100,
    LT_CONTENT_TEXT TYPE YBCS_SWS_MAIL-CONTENT_TEXT WITH HEADER LINE.

  CLEAR:
    CS_MAIL,
    CV_MAIL_ERROR.

  CS_MAIL-RECEIVER = IS_APPROVER-EMAIL.

  "决定发送邮件的语言
  IF IS_APPROVER-MAIL_LANGU IS NOT INITIAL.
    LV_MAIL_LANGU = IS_APPROVER-MAIL_LANGU.
  ELSE.
    LV_MAIL_LANGU = IV_CNFG_LANGU.
  ENDIF.
  IF LV_MAIL_LANGU IS INITIAL.
    LV_MAIL_LANGU = '1'.
  ENDIF.

  CONDENSE:
    IS_REQUEST-SUBJECT1,
    IS_REQUEST-SUBJECT2,
    IS_REQUEST-SUBJECT3.
  CASE LV_MAIL_LANGU.
    WHEN '1'.
      CS_MAIL-SUBJECT = IS_REQUEST-SUBJECT1.
      LV_CREATOR = IS_CREATOR-NAME1.
      LV_APPROVER = IS_APPROVER-NAME1.
    WHEN 'E'.
      CS_MAIL-SUBJECT = IS_REQUEST-SUBJECT2.
      LV_CREATOR = IS_CREATOR-NAME2.
      LV_APPROVER = IS_APPROVER-NAME2.
    WHEN 'Z'.
      CS_MAIL-SUBJECT = IS_REQUEST-SUBJECT3.
      LV_CREATOR = IS_CREATOR-NAME3.
      LV_APPROVER = IS_APPROVER-NAME3.
    WHEN OTHERS.
  ENDCASE.

  SELECT *
    INTO TABLE LT_T100
    FROM T100
   WHERE SPRSL = LV_MAIL_LANGU
     AND ARBGB = 'YBC_SWS_MAIL'.
  IF SY-SUBRC <> 0.
    CV_MAIL_ERROR = 'X'.
  ELSE.
    SELECT SINGLE
      *
      INTO LS_SWS_CONTR
      FROM YBC_SWS_CONTR
     WHERE PARAM IN ('SWIFTSAP_HOST', 'SWIFTSAPHOST')
       AND ACTIVE = 'X'.

    "http://localhost:52809/webapp/index.html#/Inbox/7446A0A1157D1EDB9A9167FA87B43989/?Requestid=000000500044
    LV_REQINFO = IS_REQUEST-REQUESTID.
    LV_REQURL = LS_SWS_CONTR-VALUE && '/sap/bc/ui5_ui5/sap/yfioriswiftsap/index.html#/Inbox/'
                                   && IS_APPROVER-USERID &&'/?Requestid='.
    LV_REQURL = LV_REQURL && IS_REQUEST-REQUESTID.

    PERFORM FORM_SET_HTML_HEADER USING CS_MAIL-SUBJECT CHANGING LV_HTML.

    SORT LT_T100 BY MSGNR.
    LOOP AT LT_T100 INTO LS_T100.
      LV_TEXT = LS_T100-TEXT.
      REPLACE ALL OCCURRENCES OF '&1' IN LV_TEXT WITH LV_APPROVER.
      REPLACE ALL OCCURRENCES OF '&2' IN LV_TEXT WITH LV_CREATOR.
      REPLACE ALL OCCURRENCES OF '&3' IN LV_TEXT WITH LV_REQINFO.
      REPLACE ALL OCCURRENCES OF '&4' IN LV_TEXT WITH IS_REQUEST-BUSINESSID.

      "保持翻译后Mail结构和中文的一致，翻译后空行没有记录
      LV_TIMES = LS_T100-MSGNR - LV_MSGNR_LAST - 1.
      IF LV_TIMES > 0.
        DO LV_TIMES TIMES.
          CONCATENATE LV_HTML '<br>' INTO LV_HTML.
        ENDDO.
      ENDIF.

      IF LS_T100-MSGNR = '005'.
        CONCATENATE LV_HTML '<br><a href="'  LV_REQURL '">' LV_TEXT '</a>' INTO LV_HTML.
      ELSE.
        CONCATENATE LV_HTML '<br>' LV_TEXT INTO LV_HTML.
      ENDIF.
      LV_MSGNR_LAST = LS_T100-MSGNR.
    ENDLOOP.

*    DO 8 TIMES.
*      CLEAR LT_CONTENT_TEXT.
*      MESSAGE ID 'YBC_SWS_MAIL' TYPE 'S' NUMBER SY-INDEX
*        INTO LT_CONTENT_TEXT-LINE
*        WITH LV_APPROVER LV_CREATOR LV_REQINFO IS_REQUEST-BUSINESSID.
*      IF SY-INDEX = 5.
*        CONCATENATE LV_HTML '<br><a href="'  LV_REQURL '">' LT_CONTENT_TEXT-LINE '</a>' INTO LV_HTML.
*      ELSE.
*        CONCATENATE LV_HTML '<br>' LT_CONTENT_TEXT-LINE INTO LV_HTML.
*      ENDIF.
*    ENDDO.

    LV_HTML = LV_HTML && '</body></html>'.

    "CS_MAIL-CONTENT_TEXT = LT_CONTENT_TEXT[].
    CS_MAIL-CONTENT_HTML = LV_HTML.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FORM_GET_USER_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      <-- CS_APPROVER
*&---------------------------------------------------------------------*
FORM FORM_GET_USER_DATA  CHANGING CS_APPROVER TYPE YBCS_SWS_APPROVER.
  DATA:
    LV_USER_EXIST TYPE C,
    LS_USER       TYPE YBC_SWS_USER.

  IF CS_APPROVER-USERID IS NOT INITIAL.
    SELECT SINGLE *
      INTO LS_USER
      FROM YBC_SWS_USER
     WHERE USERID = CS_APPROVER-USERID.
  ENDIF.


  IF LS_USER IS INITIAL AND CS_APPROVER-EXTUSID IS NOT INITIAL.
    SELECT SINGLE *
      INTO LS_USER
      FROM YBC_SWS_USER
     WHERE EXTUSID = CS_APPROVER-EXTUSID.
  ENDIF.

  IF LS_USER IS INITIAL AND CS_APPROVER-SAPID IS NOT INITIAL.
    SELECT SINGLE *
      INTO LS_USER
      FROM YBC_SWS_USER
     WHERE SAPID = CS_APPROVER-SAPID.
  ENDIF.

  IF LS_USER IS NOT INITIAL.
    LV_USER_EXIST = 'X'.

    CS_APPROVER-USERID = LS_USER-USERID.
    CS_APPROVER-EXTUSID  = LS_USER-EXTUSID.
    CS_APPROVER-SAPID  = LS_USER-SAPID.
    CS_APPROVER-EMAIL  = LS_USER-EMAIL.
    CS_APPROVER-USERTY = LS_USER-USERTY.
    CS_APPROVER-TEL    = LS_USER-TEL.
    CS_APPROVER-WECHAT = LS_USER-WECHAT.
    CS_APPROVER-NAME1  = LS_USER-NAME1.
    CS_APPROVER-NAME2  = LS_USER-NAME2.
    CS_APPROVER-NAME3  = LS_USER-NAME3.
    CS_APPROVER-FIELD1 = LS_USER-FIELD1.
    CS_APPROVER-FIELD2 = LS_USER-FIELD2.
    CS_APPROVER-FIELD3 = LS_USER-FIELD3.
  ELSE.

    IF CS_APPROVER-SAPID IS NOT INITIAL.
      "取名称
      SELECT SINGLE
        NAME_TEXT
        INTO CS_APPROVER-NAME1
        FROM V_USERNAME
       WHERE BNAME = CS_APPROVER-SAPID.

      CS_APPROVER-NAME2 = CS_APPROVER-NAME1.
      CS_APPROVER-NAME3 = CS_APPROVER-NAME1.

      "取Mail
      SELECT SINGLE ADR6~SMTP_ADDR
          FROM ADR6
         INNER JOIN USR21
            ON ADR6~ADDRNUMBER = USR21~ADDRNUMBER
           AND ADR6~PERSNUMBER = USR21~PERSNUMBER
          INTO CS_APPROVER-EMAIL
         WHERE USR21~BNAME = CS_APPROVER-SAPID.
    ENDIF.
  ENDIF.

ENDFORM.
